# 使用官方的 Playwright Python 镜像，它内置了所有依赖
FROM mcr.microsoft.com/playwright/python:v1.45.0-jammy

# 设置工作目录
WORKDIR /app

# 复制依赖文件并安装
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

# 关键修正：重新加回 Playwright 浏览器实例的安装命令
RUN playwright install --with-deps

# 复制所有项目文件到工作目录
COPY . .

# 切换到 Playwright 镜像提供的非 root 用户
USER pwuser

# 暴露端口
EXPOSE 8000

# 启动应用
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1"]
